import time

import requests

base_url = "http://testm.10jqka.com.cn/fuyao/prompt2data/service/prompt/v1"


# base_url = "http://internal-idc-equ.ainvest.com/ind/fuyao-prompt2data-service/prompt/v1"
def data_query(params):
    url = base_url + "/data/query"
    header = {'Content-Type': 'application/x-www-form-urlencoded'}
    start_time = time.time()  # 记录开始时间
    try:
        response = requests.post(url=url, data=params, headers=header, timeout=10)
        elapsed_time = time.time() - start_time
        print(f"请求url:{url},请求状态：{response.status_code},请求参数：{params} ,请求耗时: {elapsed_time:.4f} 秒")
        response.raise_for_status()  # 检查请求是否成功（状态码 200）
        result_data = response.json()
        if result_data.get("status_code") != 0:
            print.error(f"response is :{result_data},API请求失败: {result_data.get('status_msg')}")
            return None
        return result_data
    except Exception as e:
        print("HTTP请求异常:", e)
